Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for automatic opencontainer labels #313

Merged
merged 1 commit into from
Mar 2, 2021

Conversation

codrut-fc
Copy link

@codrut-fc codrut-fc commented Jan 18, 2021

Adding support for automatically setting opencontainers labels as default. Also, now there is a way to turn off automatic labeling.

It's documented here:

Using -e PLUGIN_AUTO_LABEL=false:

docker run --rm \
  -e PLUGIN_AUTO_LABEL=false  \
  -e PLUGIN_TAG=latest  \
  -e PLUGIN_REPO=octocat/hello-world  \
  -e DRONE_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
  -v $(pwd):$(pwd) \
  -w $(pwd) \
  --privileged \
  plugins/docker --dry-run

+ /usr/local/bin/docker build \
  --rm=true \
  -f Dockerfile \
  -t d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
  . \
  --pull=true

With -e PLUGIN_AUTO_LABEL=true, DRONE_REMOTE_URL, and DRONE_REPO_LINK:

docker run --rm \
  -e PLUGIN_AUTO_LABEL=true \
  -e DRONE_REMOTE_URL=https://github.com/octocat/hello-world.git \
  -e DRONE_REPO_LINK=https://github.com/octocat/hello-world \
  -e PLUGIN_TAG=latest \
  -e PLUGIN_REPO=octocat/hello-world \
  -e DRONE_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
  -v $(pwd):$(pwd) \
  -w $(pwd) \
  --privileged \
  plugins/docker \
  --dry-run

+ /usr/local/bin/docker build \
  --rm=true \
  -f Dockerfile \
  -t d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
  . \
  --pull=true \
  --label org.opencontainers.image.created=2021-01-11T17:28:58Z \
  --label org.opencontainers.image.revision=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
  --label org.opencontainers.image.source=https://github.com/octocat/hello-world.git \
  --label org.opencontainers.image.url=https://github.com/octocat/hello-world

@bradrydzewski
Copy link
Member

lets simplify things by removing the deprecated labels entirely and only using the new labels going forward. I would then recommend we use a boolean flag to disable automatic labeling, perhaps auto_label: true|false where the value defaults to true (since this is the current behavior).

@codrut-fc codrut-fc force-pushed the opencontainer-labels branch from a296e31 to bd40298 Compare January 20, 2021 18:16
@codrut-fc
Copy link
Author

codrut-fc commented Jan 20, 2021

All done @bradrydzewski

@codrut-fc
Copy link
Author

You might want to restart CI, looks like it reached docker hub's api rate limit...


if len(build.LabelSchema) > 0 {
labelSchema = append(labelSchema, build.LabelSchema...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tboerger can you confirm that label_schema values should be ignored if the user sets auto_label: false? This operation is wrapped by if build.AutoLabel { ... and I was wondering if it should be moved outside this block, or if this is fine as-is.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an option to opt-out is fine, I know some people that really asked for that.

@robertstettner
Copy link

Friendly bump 😄

@robertstettner
Copy link

@bradrydzewski Could you please merge this one?

@bradrydzewski bradrydzewski merged commit 0f6bd8a into drone-plugins:master Mar 2, 2021
@codrut-fc codrut-fc deleted the opencontainer-labels branch March 3, 2021 11:09
@tphoney tphoney added the enhancement New feature or request label Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants